﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace TreeBuilder
{
	public class DeleteBinderAction : TreeOperationAction
	{
		private readonly IBinder _binder;
		private readonly Action<DottedCanvas> _removeAction;
		private readonly Action<DottedCanvas> _addAction;

		public DeleteBinderAction(DottedCanvas canvas, IBinder binder, Action<DottedCanvas> removeAction = null, Action<DottedCanvas> addAction = null)
			: base(canvas)
		{
			_binder = binder;
			_removeAction = removeAction;
			_addAction = addAction;
		}

		public override void Execute()
		{
			_binder.From.Links.Remove(_binder);
			_binder.To.Links.Remove(_binder);

			if (_removeAction != null)
				_removeAction(Canvas);

			RemoveFromTree((UIElement) _binder);
		}

		public override void Undo()
		{
			_binder.From.Links.Add(_binder);
			_binder.To.Links.Add(_binder);

			if (_addAction != null)
				_addAction(Canvas);

			AddToTree((UIElement) _binder);
		}
	}
}
